import request from '@/utils/request'
function cstaaxios(url, ssdata, cmax, callback, updatas = []) {
  let promise
  if (typeof callback !== 'function') {
    promise = new Promise((resolve, reject) => {
      callback = function (resolvedata, rejectdata) {
        if (resolvedata) {
          resolve(resolvedata)
        } else {
          reject(rejectdata)
        }
      }
    })
  }
  ssdata.cmax = cmax
  ssdata.csta = updatas.length
  request.post(url, ssdata).then((reqdata) => {
    let { data } = reqdata
    updatas = updatas.concat(data)
    if (data.length >= cmax) {
      cstaaxios(url, ssdata, cmax, callback, updatas)
    } else {
      setTimeout(function () {
        callback(updatas)
      }, 300)
    }
  })
  return promise
}
export default cstaaxios
